<!DOCTYPE html>
<html lang="zh"
      xmlns:th="http://www.thymeleaf.org">
<head th:replace="common/fragment::top">

</head>

<body>
<div class="lyear-layout-web">
  <div class="lyear-layout-container">
    <!--左侧导航-->
    <div th:replace="common/fragment::leftmenu"></div>
    <!--End 左侧导航-->

    <!--头部信息-->
    <div th:replace="common/fragment::header"></div>
    <!--End 头部信息-->

    <!--页面主要内容-->
    <main class="lyear-layout-content">

      <div class="container-fluid">

        <div class="row">
          <div class="col-lg-12">
            <div class="card">
              <div class="card-toolbar clearfix">
                <div class="toolbar-btn-action">
                  <a class="btn btn-primary m-r-5"
                     href="#"
                     id="backup-btn">
                    <i class="mdi mdi-plus"></i>
                    备份
                  </a>
                  <!--
                  <a class="btn btn-success m-r-5" href="#!"><i class="mdi mdi-check"></i> 启用</a>
                  <a class="btn btn-warning m-r-5" href="#!"><i class="mdi mdi-block-helper"></i> 禁用</a>
                  <a class="btn btn-danger" href="#!"><i class="mdi mdi-window-close"></i> 删除</a>
                  -->
                </div>
              </div>
              <div class="card-body">
                <div class="table-responsive">
                  <table class="table table-bordered">
                    <thead>
                    <tr>
                      <!--<th>
                          <label class="lyear-checkbox checkbox-primary">
                              <input type="checkbox" id="check-all">
                              <span></span>
                          </label>
                      </th>-->
                      <th>序号</th>
                      <th hidden="hidden">id</th>
                      <th>备份文件名</th>
                      <th>备份日期</th>
                      <th>备注</th>
                      <th>文件大小</th>
                      <th>操作</th>
                    </tr>
                    </thead>
                    <tbody th:each="dbPO:${dblist}">
                    <tr>
                      <td th:text="${dbPOStat.index+1}"></td>
                      <td hidden="hidden" th:text="${dbPO.id}"></td>
                      <td th:text="${dbPO.filename}"></td>
                      <td th:text="${#dates.format(dbPO.createTime,'yyyy-MM-dd HH:mm:ss')}"></td>

                      <td style="word-break:break-all; word-wrap:break-word; white-space:inherit"><p
                          th:text="${dbPO.comment}"></p></td>
                      <td th:text="|${dbPO.size/1024}K|"></td>
                      <td>
                        <div class="btn-group">
                          <a class="btn btn-xs btn-default"
                             data-toggle="tooltip"
                             th:href="'/database/editdb.do?id='+${dbPO.id}" title="编辑">
                            <i class="mdi mdi-pencil"></i>
                          </a>
                          <a class="btn btn-xs btn-default deletedb-btn"
                             data-toggle="tooltip"
                             th:href="${dbPO.id}"
                             title="删除">
                            <i class="mdi mdi-window-close"></i>
                          </a>

                        </div>
                      </td>
                    </tr>

                    </tbody>
                  </table>
                </div>
                <!--分页标签-->
                <nav>
                  <!--10页以内-->
                  <th:block th:if="${totalPage lt 10}">
                    <ul class="pagination pagination-sm">
                      <!--后置箭头-->
                      <li th:class="${currentPage>1?'':'disabled'}">
                                                    <span class="leftarrow"
                                                          th:href="${currentPage}-1">
                                                        <span><i
                                                            class="mdi mdi-chevron-left"></i></span>
                                                    </span>
                      </li>

                      <li th:class="${currentPage==1?'active':''} + ' label'"
                          th:if="${totalPage ge 1}">
                        <a href="/sys/loglist.do?page=1">1</a></li>
                      <li th:class="${currentPage==2?'active':''} + ' label'"
                          th:if="${totalPage ge 2}">
                        <a href="/sys/loglist.do?page=2">2</a></li>
                      <li th:class="${currentPage==3?'active':''} + ' label'"
                          th:if="${totalPage ge 3}">
                        <a href="/sys/loglist.do?page=3">3</a></li>
                      <li th:class="${currentPage==4?'active':''} + ' label'"
                          th:if="${totalPage ge 4}">
                        <a href="/sys/loglist.do?page=4">4</a></li>
                      <li th:class="${currentPage==5?'active':''} + ' label'"
                          th:if="${totalPage ge 5}">
                        <a href="/sys/loglist.do?page=5">5</a></li>
                      <li th:class="${currentPage==6?'active':''} + ' label'"
                          th:if="${totalPage ge 6}">
                        <a href="/sys/loglist.do?page=6">6</a></li>
                      <li th:class="${currentPage==7?'active':''} + ' label'"
                          th:if="${totalPage ge 7}">
                        <a href="/sys/loglist.do?page=7">7</a></li>
                      <li th:class="${currentPage==8?'active':''} + ' label'"
                          th:if="${totalPage ge 8}">
                        <a href="/sys/loglist.do?page=8">8</a></li>
                      <li th:class="${currentPage==9?'active':''} + ' label'"
                          th:if="${totalPage ge 9}">
                        <a href="/sys/loglist.do?page=9">9</a></li>
                      <li th:class="${currentPage==10?'active':''} + ' label'"
                          th:if="${totalPage ge 10}">
                        <a href="/sys/loglist.do?page=10">10</a></li>

                      <!--后置箭头-->
                      <li th:class="${currentPage<totalPage?'':'disabled'}">
                                                    <span class="rightarrow"
                                                          th:href="${currentPage}+1">
                                                        <span><i class="mdi mdi-chevron-right"></i></span>
                                                    </span>
                      </li>
                    </ul>

                  </th:block>
                  <!--超过10页-->
                  <th:block th:if="${totalPage ge 10}">
                    <ul class="pagination pagination-sm">
                      <!--后置箭头-->
                      <li th:class="${currentPage>1?'':'disabled'}">
                                                    <span class="leftarrow"
                                                          th:href="${currentPage}-1">
                                                        <span><i
                                                            class="mdi mdi-chevron-left"></i></span>
                                                    </span>
                      </li>

                      <!--首页-->
                      <li th:class="${currentPage==1?'active':''} + ' label'"
                          th:if="${totalPage ge 1}">
                        <a href="/sys/loglist.do?page=1">1</a></li>
                      <li th:class="${currentPage==2?'active':''} + ' label'"
                          th:if="${currentPage lt 3}">
                        <a href="/sys/loglist.do?page=2">2</a></li>
                      <li th:class="${currentPage==3?'active':''} + ' label'"
                          th:if="${currentPage lt 3}">
                        <a href="/sys/loglist.do?page=3">3</a></li>
                      <li th:class="${currentPage==4?'active':''} + ' label'"
                          th:if="${currentPage lt 3}">
                        <a href="/sys/loglist.do?page=3">4</a></li>

                      <!--前省略号-->
                      <li th:if="${befor_ellipsis eq true}"><span th:text="..."> </span></li>

                      <!--中间分页current 前一页-->
                      <li th:if="${mid eq true}">
                        <a th:href="'/sys/loglist.do?page='+${midb}" th:text="${currentPage}-1"></a>
                      </li>
                      <!--中间分页current-->
                      <li th:class="${'active'}" th:if="${mid eq true}">
                        <a th:href="'/sys/loglist.do?page='+${currentPage}"
                           th:text="${currentPage}"></a>
                      </li>
                      <!--中间分页current 后一页-->
                      <li th:if="${mid eq true}">
                        <a th:href="'/sys/loglist.do?page='+${mida}" th:text="${currentPage}+1"></a>
                      </li>

                      <!--后省略号-->
                      <li th:if="${after_ellipsis  eq true}"><span th:text="..."></span></li>

                      <li th:class="${currentPage== last02?'active':''} + ' label'"
                          th:if="${currentPage gt last02}">
                        <a th:href="'/sys/loglist.do?page='+last02" th:text="${last02}">2</a>
                      </li>
                      <li th:class="${currentPage== last01?'active':''} + ' label'"
                          th:if="${currentPage  gt last02}">
                        <a th:href="'/sys/loglist.do?page='+last01" th:text="${last01}">2</a>
                      <li th:class="${currentPage==last00?'active':''} + ' label'"
                          th:if="${currentPage  gt last02}">
                        <a th:href="'/sys/loglist.do?page='+last00" th:text="${last00}">2</a>
                        <!--尾页-->
                      <li th:class="${currentPage==totalPage?'active':''} + ' label'">
                        <a th:href="'/sys/loglist.do?page='+${totalPage}"
                           th:text="${totalPage}">10</a></li>

                      <!--后置箭头-->
                      <li th:class="${currentPage<totalPage?'':'disabled'}">
                                                    <span class="rightarrow"
                                                          th:href="${currentPage}+1">
                                                        <span><i class="mdi mdi-chevron-right"></i></span>
                                                    </span>
                      </li>
                    </ul>

                  </th:block>

                </nav>
                <!--分页标签结束-->
              </div>
            </div>
          </div>

        </div>

      </div>
    </main>
    <!--End 页面主要内容-->
    <!--End 页面主要内容-->
  </div>
</div>
<div th:replace="common/fragment::tail-script"></div>
<script type="text/javascript">

  // 备份操作
  function dbbackup() {
    console.log('start backup')
    $.confirm({
      title: '备份数据库？',
      content: '开始备份!!! ',
      type: 'orange',
      typeAnimated: false,
      buttons: {
        confirm: {
          text: '确认',
          action: function () {
            post_ajax('/database/backup.ajax', {}, '/database/dblist.do')
          }
        },
        cancel: {
          text: '取消',
          action: function () {

          }
        }
      }
    });

  }

  // 删除备份
  function delete_btn(e){
    let data={
      id:$(e).attr('href')
    }

    $.confirm({
      title: '删除数据库？',
      content: '确定删除数据库!!! ',
      type: 'orange',
      typeAnimated: false,
      buttons: {
        confirm: {
          text: '确认',
          action: function () {
            post_ajax('/database/deletedb.ajax', data, '/database/dblist.do')
          }
        },
        cancel: {
          text: '取消',
          action: function () {

          }
        }
      }
    });
    return false;
  }

  $(document).ready(function(){
    $('#backup-btn').click(function (e) {
      dbbackup()
      e.preventDefault()
    })

        $('.deletedb-btn').each(function (i,e) {
          $(e).click(function (event) {
            delete_btn(e)
            event.preventDefault()
          })
        })
  });

</script>
</body>
</html>